package m.html.form;

import m.html.element.Button;
import m.html.element.Element;
import m.html.element.Icon;
import m.html.element.Text;
import m.html.element.attr.ButtonType;
import m.html.element.attr.Size;
import m.html.element.other.IElement;

public class FormHtml extends AbstractFormItem<FormHtml>{
    private final StringBuilder html;

    /**
     * vue模板html部分
     */
    protected FormHtml(String title,String html){
        this.setTitle(new Text(title));
        this.html=new StringBuilder();
        this.html.append(html);
    }
    public static FormHtml ins(String title,String html){
        return new FormHtml(title,html);
    }
    public static FormHtml ins(String title,IElement ele){
        return FormHtml.ins(title,ele.toString());
    }
    public static FormHtml html(String html){
        return FormHtml.ins("",html);
    }
    public static FormHtml element(IElement ele){
        return FormHtml.ins("",ele.toString());
    }

    public static Element getSelectButton(String click){
        return new Button(Size.SMALL, ButtonType.PRIMARY).E(new Text("选择"))
                .setExtend("@click=\""+click+"\"");
    }
    public static Element getClearButton(String click){
        return new Icon("icon-icon-52").A(":size", "13")
                .setExtend("@click=\""+click+"\"");
    }
    public FormHtml append(String html){
        this.html.append(html);
        return this;
    }
    public FormHtml append(IElement ele){
        this.html.append(ele.toString());
        return this;
    }

    @Override
    protected IElement getItemElement() {
        return new Text(this.html.toString());
    }
}
